package yaq.mini.weibo.leafwb.mapper;

import yaq.mini.weibo.leafwb.pojo.User;
import org.apache.ibatis.annotations.Delete;
import org.apache.ibatis.annotations.Insert;
import org.apache.ibatis.annotations.Select;
import org.apache.ibatis.annotations.Update;

import java.util.List;

public interface UserMapper {
    User getFullUserByID(String userId);

    @Select("select * from user where userId=#{userId}")
    User getUserByID(String userId);

    @Select("select * from user where userId=#{userId} and password=#{password}")
    User getUserByLogin(String userId,String password);

    @Select("select * from user where type='普通用户' order by registerDate desc")
    List<User> listUserExceptRoot();

    @Select("select headPictureUrl from user where userId=#{userId}")
    String getHeadUrlById(String userId);

    @Select("select isAllowShare from user where userId=#{userId}")
    String isAllowShare(String userId);

    @Insert("insert into User(userId,name,passw ord,sex,mail,address,headPictureUrl,introduction,birthday,registerDate,isAllowShare) Values(#{userId},#{name},#{password},#{sex},#{mail},#{address},#{headPictureUrl},#{introduction},#{birthday},#{registerDate},#{isAllowShare})")
    int insert(User user);

    @Update("update user set headPictureUrl=#{headPictureUrl} where userId=#{userId}")
    int updateByHeadUrl(String userId,String headPictureUrl);

    @Update("update user set name=#{name},address=#{address},sex=#{sex},birthday=#{birthday},introduction=#{introduction} where userId=#{userId}")
    int updateUserMesById(String userId,String name,String address,String sex, String birthday,String introduction);

    @Update("update user set password=#{newPassword} where userId=#{userId}")
    int updatePassword(String userId,String newPassword);

    @Update("update user set isAllowShare=#{isAllowShare} where userId=#{userId}")
    int updateAllowShare(String userId,String isAllowShare);

    @Update("update user set name=#{name},password=#{password},mail=#{mail},type=#{type},headPictureUrl=#{headPictureUrl},isAllowShare=#{isAllowShare} where userId=#{userId}")
    int update(User user);

    @Delete("delete from user where userId=#{userId}")
    int delete(User user);

}
